package model

import (
	"gorm.io/gorm"
	"share-chat/global"
	"time"
)

type Comment struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:评论ID;primaryKey;not null;" form:"id" json:"id"`                                            // 评论ID
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" form:"user_id" json:"user_id"`                                                 // 用户ID
	ShareId   int32          `gorm:"column:share_id;type:int;comment:分享ID;not null;" form:"share_id" json:"share_id"`                                              // 分享ID
	Content   string         `gorm:"column:content;type:varchar(255);comment:评论内容;not null;" form:"content" json:"content"`                                      // 评论内容
	RootId    int32          `gorm:"column:root_id;type:int;comment:根评论ID;default:NULL;" form:"root_id" json:"root_id"`                                           // 根评论ID
	UpId      int32          `gorm:"column:up_id;type:int;comment:上一级ID;default:NULL;" form:"up_id" json:"up_id"`                                                 // 上一级ID
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:发布时间;not null;default:CURRENT_TIMESTAMP(3);" form:"created_at" json:"created_at"` // 发布时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" form:"updated_at" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" form:"deleted_at" json:"deleted_at"`
}

func (c *Comment) TableName() string {
	return "share"
}

func (c *Comment) AddComment() error {
	return global.DB.Create(&c).Error
}
